package loaderData
{
	import flash.display.BitmapData;
	import flash.display.Loader;
	import flash.events.Event;
	import flash.events.IOErrorEvent;
	import flash.events.ProgressEvent;
	import flash.net.URLRequest;
	/**
	 * 位图加载 
	 * @author weiping
	 * 
	 */
	public class LoaderImg extends BaseLoader
	{
		private var loader:Loader;
		
		public function LoaderImg()
		{
			loader = new Loader();
		}
		
		override public function load(url:String):void
		{
			loaderUrl = url;
			loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteEvent);
			loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIoErrorEvent);
			loader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressEvent);
			loader.contentLoaderInfo.addEventListener(Event.OPEN, onOpen);
			
			loader.load(new URLRequest(url));
		}

		override protected function onCompleteEvent(event:Event):void
		{
			this.objData = event.target.content.bitmapData as BitmapData;
			super.onCompleteEvent(event);
		}
		
		override protected function onProgressEvent(event:ProgressEvent):void
		{
			this.bytesLoadNum = event.bytesLoaded;
			this.bytesTotalNum = event.bytesTotal;
			super.onProgressEvent(event);
		}
		
		override protected function onOpen(event:Event):void
		{
			super.onOpen(event);
		}
		
		override public function clear():void
		{
			super.clear();
			removeEvent();
			loader.unload();
		}
		
		protected function removeEvent():void
		{
			loader.contentLoaderInfo.removeEventListener(Event.COMPLETE, onCompleteEvent);
			loader.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, onIoErrorEvent);
			loader.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgressEvent);
			loader.contentLoaderInfo.removeEventListener(Event.OPEN, onOpen);
		}
		
	}
}